$(document).ready(function() {
    $(".add").click(function() {
        var id = $(this).children("input").val();
        var shopname = $("#shopname").val();
        var url = "/" + shopname + "/AjaxBasket/add";
        $.post(url,
                {id: id
                }).done(function(evt) {
            // console.log(evt);
            window.location.href = window.location.href;
        });
    });
    $(".removeItem").click(function() {
        var id = $(this).children("input").val();
        var shopname = $("#shopname").val();
        var url = "/" + shopname + "/AjaxBasket/removeSingleElem";
        $.post(url,
                {id: id
                }).done(function(evt) {
            // console.log(evt);
            window.location.href = window.location.href;
        });
    });
    $(".remove").click(function() {
        var id = $(this).children("input").val();
        var all = 1;
        var shopname = $("#shopname").val();
        var url = "/" + shopname + "/AjaxBasket/removeSingleElem";
        $.post(url,
                {id: id,
                    all: all
                }).done(function(evt) {
            // console.log(evt);
            window.location.href = window.location.href;
        });
    });
    $(".link").click(function() {
        $(this).next().slideToggle("slow");
    });
    $(".payment").click(function(){
        var id = $(this).children("input").val();
        var parent = $(this).parent().prev();
        $(".paymentName").removeClass("alert-success");
        $(".paymentName").removeClass("alert-info");
        $(".paymentName").addClass("alert-info");
        $(".paymentName").children("p").text("");
        var shopname = $("#shopname").val();
        var url = "/" + shopname + "/AjaxBasket/addPayment";
        $.post(url,
                {id: id
                }).done(function(evt) {
                  parent.removeClass("alert-info");
                  parent.addClass("alert-success");
                  parent.children("p").text("Płatność została wybrana");
                  console.log(evt);
           //window.location.href = window.location.href;
        });
    });
    $(".delivery").click(function(){
        var id = $(this).children("input").val();
        var parent = $(this).parent().prev();
        $(".deliveryName").removeClass("alert-success");
        $(".deliveryName").removeClass("alert-info");
        $(".deliveryName").addClass("alert-info");
        $(".deliveryName").children("p").text("");
        var shopname = $("#shopname").val();
        var url = "/" + shopname + "/AjaxBasket/addDelivery";
        $.post(url,
                {id: id
                }).done(function(evt) {
                    console.log(id);
                  parent.removeClass("alert-info");
                  parent.addClass("alert-success");
                  parent.children("p").text("Metoda dostawy została wybrana");
            window.location.href = window.location.href;
        });
    });
});